package com.liuh.fram.io;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;


/**
 * @note 压缩抽象类
 * @author liuh
 * */
public abstract class CompressTools {

	public abstract byte[] compress(byte[] value) throws Exception;

	public abstract byte[] decompress(byte[] value) throws Exception;

	/**
	 * @note base64编码,压缩
	 * @author liuh
	 * @throws AppException
	 * */
	public String compressBase64(String inputVal) throws Exception {
		byte[] com_byte = null;
		com_byte = compress(inputVal.getBytes("utf-8"));
		String base64_compress = Base64.encodeBase64URLSafeString(com_byte);
		return base64_compress;
	}

	/**
	 * @note base64编码，解压
	 * @author liuh
	 * @throws AppException
	 * @throws UnsupportedEncodingException
	 * */
	public String decompressBase64(String value2) throws Exception {
		String outputString = null;
		byte[] decom_byte = decompress(Base64.decodeBase64(value2
				.getBytes("UTF-8")));
		outputString = new String(decom_byte, 0, decom_byte.length, "UTF-8");
		return outputString;
	}

}
